home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 April: Penguin on DISC / ADC Developer CD (1993-04) (''Penguin On DISC'')_iso / Dev.CD Apr 93.iso / Utilities / MPW Interfaces 7.1 Beta / PInterfaces / TextServices.p < prev    next >
Encoding:
Text File  |  1992-08-28  |  11.2 KB  |  321 lines  |  [TEXT/MPS ]

  1. {
  2.     File:        TextServices.p
  3.  
  4.     Contains:    Pascal interfaces to the Text Services Manager
  5.  
  6.     Written by:    Dean Yu (but only because Chris was in a meeting and Don wasn’t in his office.)
  7.  
  8.     Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12. }
  13.  
  14.  
  15. {$IFC UNDEFINED UsingIncludes}
  16. {$SETC UsingIncludes := 0}
  17. {$ENDC}
  18.  
  19. {$IFC NOT UsingIncludes}
  20.  UNIT TextServices;
  21.  INTERFACE
  22. {$ENDC}
  23.  
  24. {$IFC UNDEFINED UsingTextServices}
  25. {$SETC UsingTextServices := 1}
  26.  
  27. {$I+}
  28. {$SETC UsingTextServices := UsingIncludes}
  29. {$SETC UsingIncludes := 1}
  30. {$IFC UNDEFINED UsingTypes}
  31. {$I $$Shell(PInterfaces)Types.p}
  32. {$ENDC}
  33. {$IFC UNDEFINED UsingEvents}
  34. {$I $$Shell(PInterfaces)Events.p}
  35. {$ENDC}
  36. {$IFC UNDEFINED UsingMenus}
  37. {$I $$Shell(PInterfaces)Menus.p}
  38. {$ENDC}
  39. {$IFC UNDEFINED UsingAppleEvents}
  40. {$I $$Shell(PInterfaces)AppleEvents.p}
  41. {$ENDC}
  42. {$IFC UNDEFINED UsingErrors}
  43. {$I $$Shell(PInterfaces)Errors.p}
  44. {$ENDC}
  45. {$IFC UNDEFINED UsingComponents}
  46. {$I $$Shell(PInterfaces)Components.p}
  47. {$ENDC}
  48. {$SETC UsingIncludes := UsingTextServices}
  49.  
  50. CONST
  51.  
  52.     kTSMVersion            =    1;                        { Version of Text Services Manager }
  53.     kTextService        =    'tsvc';                    { Component type for component description }
  54.     kInputMethodService    =    'inpm';                    { Component subtype for component description }
  55.     
  56.     bTakeActiveEvent    =    15;                        { Bit set if the component takes activate events }
  57.     bScriptMask            =    $00007F00;                { Bits 8 - 14 }
  58.     bLanguageMask        =    $000000FF;                { Bits 0 - 7 }
  59.     bScriptLanguageMask    =    bScriptMask + bLanguageMask;    {Bits 0 - 14 }
  60.  
  61. { Hilite styles ... }
  62.     kCursorPosition                =    1;                { specify cursor position }
  63.     kRawText                    =    2;                { specify range of raw text }
  64.     kSelectedRawText            =    3;                { specify range of selected raw text }
  65.     kConvertedText                =    4;                { specify range of converted text }
  66.     kSelectedConvertedText        =    5;                { specify range of selected converted text }
  67.     
  68. {
  69.     Apple Event constants
  70. }
  71.  
  72.     kTextServiceClass        =    kTextService;        { Event class }
  73.     kUpdateActiveInputArea    =    'updt';                { Update the active inline area }
  74.     kPos2Offset                =    'p2st';                { Convert global coordinates to character position }
  75.     kOffset2Pos                =    'st2p';                { Convert character position to global coordinate }
  76.     kShowHideInputWindow    =    'shiw';                { show or hide the input window }
  77.     
  78.  
  79.     { Event keywords ... }
  80.  
  81.     keyAETSMDocumentRefcon    =    'refc';                { TSM document refcon }
  82.  
  83.     keyAEServerInstance    =    'srvi';                    { Server instance }
  84.     keyAETheData        =    'kdat';                    { typeText }
  85.     keyAEScriptTag        =    'sclg';                    { Script tag }
  86.     keyAEFixLength        =    'fixl';
  87.     keyAEHiliteRange    =    'hrng';                    { Hilite range array }
  88.     keyAEUpdateRange    =    'udng';                    { Update range array }
  89.     keyAEClauseOffsets    =    'clau';                    { Clause offsets array }
  90.     keyAECurrentPoint    =    'cpos';                    { Current point }
  91.     keyAEDragging        =    'bool';                    { Dragging flag }
  92.     keyAEOffset            =    'ofst';                    { Offset }
  93.     keyAERegionClass    =    'rgnc';                    { Region class }
  94.     keyAEPoint            =    'gpos';                    { Current point }
  95.     keyAEBufferSize        =    'buff';                    { Buffer size to get the text }
  96.     keyAERequestedType    =    'rtyp';                    { Requested text type }
  97.     keyAEMoveView        =    'mvvw';                    { Move view flag }
  98.     keyAELength            =    'leng';                    { Length }
  99.     keyAENextBody        =    'nxbd';                    { Next or previous body }
  100.  
  101. { optional keywords for Offset2Pos        -- 28Mar92 }
  102.  
  103.     keyAETextFont        =    'ktxf';
  104.     keyAETextPointSize    =    'ktps';
  105.     keyAETextLineHeight    =    'ktlh';
  106.     keyAETextLineAscent    =    'ktas';
  107.     keyAEAngle            =    'kang';
  108.     
  109. { optional keyword for Pos2Offset        }
  110.  
  111.     keyAELeftSide        =    'klef';                    { type Boolean }
  112.  
  113.  
  114. { optional keyword for kShowHideInputWindow    }
  115.  
  116.     keyAEShowHideInputWindow    =    'shiw';            { type Boolean }
  117.  
  118. { keyword for PinRange  }
  119.  
  120.     keyAEPinRange                =    'pnrg';            { <#6> }
  121.  
  122.  
  123. { Desc type ... }
  124.  
  125.     typeComponentInstance    =    'cmpi';                { Component instance }
  126.     typeTextRangeArray        =    'tray';                { Text range array }
  127.     typeOffsetArray            =    'ofay';                { Offset array }
  128.     typeIntlWritingCode        =    'intl';                { Script code }
  129.     typeQDPoint                =    'QDpt';                { QuickDraw point }
  130.     typeAEText                =    'tTXT';                { Apple Event text }
  131.     typeText                =    'TEXT';                { Plain text }
  132.     
  133.     typeTextRange            =    'txrn';                { <#6> }
  134.  
  135.  
  136. {
  137.     Error codes
  138. }
  139.  
  140.     tsmComponentNoErr    =    0;                        { Component result = no error }
  141.     
  142.     tsmUnsupScriptLanguageErr    =    -2500;
  143.     tsmInputMethodNotFoundErr    =    -2501;
  144.     tsmNotAnAppErr                =    -2502;            { Not an application error }
  145.     tsmAlreadyRegisteredErr        =    -2503;            { Attemp to register again }
  146.     tsmNeverRegisteredErr        =    -2504;            { App never registered.  (Not TSM Aware) }
  147.     tsmInvalidDocIDErr            =    -2505;            { Invalid TSM documentation ID }
  148.     tsmTSMDocBusyErr            =    -2506;            { Document is still active }
  149.     tsmDocNotActiveErr            =    -2507;            { Document is not active }
  150.     tsmNoOpenTSErr                =    -2508;            { No open text service }
  151.     tsmCantOpenComponentErr        =    -2509;            { Can’t open the component }
  152.     tsmTextServiceNotFoundErr    =    -2510;            { No text service found }
  153.     tsmDocumentOpenErr            =    -2511;            { There are open documents }
  154.     tsmUseInputWindowErr        =    -2512;            { Not TSM aware because an input window is being used }
  155.     tsmTSHasNoMenuErr            =    -2513;            { The Text Service has no menu }
  156.     tsmTSNotOpenErr                =    -2514;            { Text service is not open }
  157.     tsmComponentAlreadyOpenErr    =    -2515;            { Text service already open for document }
  158.  
  159.     tsmInputMethodIsOldErr        =    -2516;            { Returned by GetDefaultInputMethod }
  160.     tsmScriptHasNoIMErr            =    -2517;            { Script has no input method or is using old input method }
  161.     tsmUnsupportedTypeErr        =    -2518;            { unSupported interface type error }
  162.     tsmUnknownErr                =    -2519;            { Any other errors }
  163.  
  164.     kTSMOutsideOfBody            =    1;
  165.     kTSMInsideOfBody            =    2;
  166.     kTSMInsideOfActiveInputArea    =    3;
  167.     
  168.     kNextBody                    =    1;
  169.     kPreviousBody                =    2;
  170.     
  171.     errOffsetInvalid            =    -1800;
  172.     errOffsetIsOutsideOfView    =    -1801;
  173.     errTopOfDocument            =    -1810;
  174.     errTopOfBody                =    -1811;
  175.     errEndOfDocument            =    -1812;
  176.     errEndOfBody                =    -1813;
  177.     
  178. TYPE
  179.     TextRangeHandle    =    ^TextRangePtr;
  180.     TextRangePtr    =    ^TextRange;
  181.     TextRange        =    Record                            { typeTextRange }
  182.                             fStart:            Longint;
  183.                             fEnd:            Longint;
  184.                             fHiliteStyle:    Integer;
  185.                         End;
  186.                         
  187.     TextRangeArrayHandle    =    ^TextRangeArrayPtr;
  188.     TextRangeArrayPtr        =    ^TextRangeArray;
  189.     TextRangeArray            =    Record                    { typeTextRangeArray }
  190.                                     fNumOfRanges:    Integer;
  191.                                     fRange:            Array [0..0] of TextRange;
  192.                                 End;
  193.                                 
  194.     OffsetArrayHandle    =    ^OffsetArrayPtr;
  195.     OffsetArrayPtr        =    ^OffsetArray;
  196.     OffsetArray            =    Record                        { typeOffsetArray }
  197.                                 fNumOfOffsets:    Integer;
  198.                                 fOffset:        Array [0..0] of Longint;
  199.                             End;
  200.  
  201.  
  202.     TextServicesInfoPtr    =    ^TextServiceInfo;
  203.     TextServiceInfo        =    Record
  204.                                 fComponent:        Component;
  205.                                 fItemName:        Str255;
  206.                             End;
  207.                             
  208.     TextServiceListHandle    =    ^TextServiceListPtr;
  209.     TextServiceListPtr        =    ^TextServiceList;
  210.     TextServiceList            =    Record
  211.                                     fTextServiceCount:    Integer;
  212.                                     fServices:             Array [0..0] of TextServiceInfo;
  213.                                 End;
  214.                             
  215.     ScriptLanguageRecord    =    Record
  216.                                     fScript:    ScriptCode;
  217.                                     fLanguage:    LangCode;
  218.                                 End;
  219.                                 
  220.     ScriptLanguageSupportHandle    =    ^ScriptLanguageSupportPtr;
  221.     ScriptLanguageSupportPtr    =    ^ScriptLanguageSupport;
  222.     ScriptLanguageSupport        =    Record
  223.                                         fScriptLanguageCount:    Integer;
  224.                                         fScriptLanguageArray:    Array [0..0] of ScriptLanguageRecord;
  225.                                     End;
  226.  
  227.     InterfaceTypeList    =    Array [0..0] of OSType;
  228.     
  229.     TSMDocumentID        =    Ptr;
  230.     
  231. {
  232.     Text Services Routines
  233. }
  234.  
  235. Function NewTSMDocument(numOfInterface: Integer; supportedInterfaceTypes: InterfaceTypeList; VAR idocID: TSMDocumentID; refCon: Longint): OSErr;
  236.     INLINE $303C, $0000, $AA54;
  237. Function DeleteTSMDocument(idocID: TSMDocumentID): OSErr;
  238.     INLINE $303C, $0001, $AA54;
  239. Function ActivateTSMDocument(idocID: TSMDocumentID): OSErr;
  240.     INLINE $303C, $0002, $AA54;
  241. Function DeactivateTSMDocument(idocID: TSMDocumentID): OSErr;
  242.     INLINE $303C, $0003, $AA54;
  243. Function TSMEvent(VAR event: EventRecord): Boolean;
  244.     INLINE $303C, $0004, $AA54;
  245. Function TSMMenuSelect(menuResult: Longint): Boolean;
  246.     INLINE $303C, $0005, $AA54;
  247. Function SetTSMCursor(mousePos: Point): Boolean;
  248.     INLINE $303C, $0006, $AA54;
  249. Function FixTSMDocument(idocID: TSMDocumentID): OSErr;
  250.     INLINE $303C, $0007, $AA54;
  251. Function GetServiceList(numOfInterface: Integer; supportedInterfaceTypes: InterfaceTypeList; VAR serviceInfo: TextServiceListHandle; VAR seedValue: Longint): OSErr;
  252.     INLINE $303C, $0008, $AA54;
  253. Function OpenTextService(idocID: TSMDocumentID; aComponent: Component; VAR aComponentInstance: ComponentInstance): OSErr;
  254.     INLINE $303C, $0009, $AA54;
  255. Function CloseTextService(idocID: TSMDocumentID; aComponentInstance: ComponentInstance): OSErr;
  256.     INLINE $303C, $000A, $AA54;
  257.  
  258. Function SendAEFromTSMComponent(VAR theAppleEvent: AppleEvent; VAR reply: AppleEvent; sendMode: AESendMode; sendPriority: AESendPriority; timeOutInTicks: Longint; idleProc: IdleProcPtr; filterProc: EventFilterProcPtr): OSErr;
  259.     INLINE $303C, $000B, $AA54;
  260. Function InitTSMAwareApplication: OSErr;
  261.     INLINE $303C, $0014, $AA54;
  262. Function CloseTSMAwareApplication: OSErr;
  263.     INLINE $303C, $0015, $AA54;
  264.  
  265.  
  266. Function SetDefaultInputMethod(ts: Component; VAR slRecord: ScriptLanguageRecord): OSErr;
  267.     INLINE $303C, $000C, $AA54;
  268. Function GetDefaultInputMethod(VAR ts: Component; VAR slRecord: ScriptLanguageRecord): OSErr;
  269.     INLINE $303C, $000D, $AA54;
  270. Function SetTextServiceLanguage(VAR slRecord: ScriptLanguageRecord): OSErr;
  271.     INLINE $303C, $000E, $AA54;
  272. Function GetTextServiceLanguage(VAR slRecord: ScriptLanguageRecord): OSErr;
  273.     INLINE $303C, $000F, $AA54;
  274. Function UseInputWindow(idocID: TSMDocumentID; useWindow: Boolean): OSErr;
  275.     INLINE $303C, $0010, $AA54;
  276. Function NewServiceWindow(wStorage: Ptr; boundsRect: Rect; title: Str255; 
  277.     visible: Boolean; theProc: Integer; behind: WindowPtr; goAwayFlag: BOOLEAN;
  278.     ts: ComponentInstance; VAR window: WindowPtr): OSErr;
  279.     INLINE $303C, $0011, $AA54;
  280. Function CloseServiceWindow(window: WindowPtr): OSErr;
  281.     INLINE $303C, $0012, $AA54;
  282. Function GetFrontServiceWindow(VAR window: WindowPtr): OSErr;
  283.     INLINE $303C, $0013, $AA54;
  284. Function FindServiceWindow(thePoint: Point; VAR theWindow: WindowPtr): Integer;
  285.     INLINE $303C, $0017, $AA54;
  286.  
  287. {
  288.     Low level Text Services routines
  289. }
  290.  
  291. Function GetScriptLanguageSupport(ts: ComponentInstance; VAR scriptHandle: ScriptLanguageSupportHandle): ComponentResult;
  292.     INLINE $2F3C, $0400, $0001, $7000, $A82A;
  293. Function InitiateTextService(ts: ComponentInstance): ComponentResult;
  294.     INLINE $2F3C, $0000, $0002, $7000, $A82A;
  295. Function TerminateTextService(ts: ComponentInstance): ComponentResult;
  296.     INLINE $2F3C, $0000, $0003, $7000, $A82A;
  297. Function ActivateTextService(ts: ComponentInstance): ComponentResult;
  298.     INLINE $2F3C, $0000, $0004, $7000, $A82A;
  299. Function DeactivateTextService(ts: ComponentInstance): ComponentResult;
  300.     INLINE $2F3C, $0000, $0005, $7000, $A82A;
  301. Function TextServiceEvent(ts: ComponentInstance; numOfEvents: Integer; VAR event: EventRecord): ComponentResult;
  302.     INLINE $2F3C, $0000, $0006, $7000, $A82A;
  303. Function GetTextServiceMenu(ts: ComponentInstance; VAR serviceMenu: MenuHandle): ComponentResult;
  304.     INLINE $2F3C, $0000, $0007, $7000, $A82A;
  305. Function TextServiceMenuSelect(ts: ComponentInstance; serviceMenu: MenuHandle; item: Integer): ComponentResult;
  306.     INLINE $2F3C, $0000, $0008, $7000, $A82A;
  307. Function FixTextService(ts: ComponentInstance): ComponentResult;
  308.     INLINE $2F3C, $0000, $0009, $7000, $A82A;
  309. Function SetTextServiceCursor(ts: ComponentInstance; mousePos: Point): ComponentResult;
  310.     INLINE $2F3C, $0000, $000A, $7000, $A82A;
  311. Function HidePaletteWindows(ts: ComponentInstance): ComponentResult;
  312.     INLINE $2F3C, $0000, $000B, $7000, $A82A;
  313.  
  314.  
  315. {$ENDC} { UsingTextServices }
  316.  
  317. {$IFC NOT UsingIncludes}
  318.  END.
  319. {$ENDC}
  320.  
  321.